<template>
	<view class="page">
		<!-- #ifndef MP-WEIXIN-->
		<my-navbar leftText="流水详情"  @leftClick="back" ></my-navbar>
		<!-- #endif -->
		<view class="content">
			<view class="flex-btw">
				<text class="prop">流水号</text>
				<text>{{data.id}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">关联订单</text>
				<text>{{data.order_sn}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">流水类型</text>
				<text>{{data.typeName}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">金额</text>
				<text>{{data.balance_change}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">变动后差额</text>
				<text style="color:#E84B4B">{{data.balance_left}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">创建日期</text>
				<text>{{data.createdTime}}</text>
			</view>
			<view class="flex-btw">
				<text class="prop">状态</text>
				<text v-if="data.status==2" style="color:#19be6b">正常</text>
				<text v-else-if="data.status==1" style="color:#ff9900">确认中</text>
				<text v-else-if="data.status==0" style="color:#c8c9cc">已关闭</text>
			</view>
			<view class="btns" v-if="data.status==1">
				<view class="btn flex-center" @click="submit(1)">已收到退款</view>
				<view class="btn flex-center" @click="submit(0)">未收到退款</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {$https} from '@/static/js/request.js';
	export default {
		data() {
			return {
				data:{}
			};
		},
		onLoad(option){
			$https('GET','getBalanceWaterDetail',{id:option.id},res=>{
				if(res.data.errcode==0){
					var list = res.data.data;
					switch(list.type){
						case 0:{list.typeName = '平台多退';break;};
						case 1:{list.typeName = '平台欠收';break;};
						case 2:{list.typeName = '自主少补';break;};
						case 3:{list.typeName = '自主抵扣';break;};
						case 4:{list.typeName = '平台结清';break;};
						case 5:{list.typeName = '自主结清';break;};
						case 6:{list.typeName = '平台退款';break;};
					}
					var ms = Number(list.created_at+'000');
					var now = new Date();
					now.setTime(ms);
					var date = now.getFullYear()+"-" + (now.getMonth()+1) + "-" + now.getDate()+ ' ' + now.getHours()+':'+now.getMinutes()+':'+now.getSeconds()
					list.createdTime = date;
					this.data = list;
				}else{
					uni.showToast({
						title: res.data.errmsg,
						icon:'none'
					});
				}
			})
		},
		methods:{
			submit(type){
				let title = type==1?'确认已收到平台的退款吗':'确认关闭平台的退款吗'
				uni.showModal({
				    title: title,
				    success: (res)=> {
				        if (res.confirm) {
							let params = {
								id:this.data.id,
								confirm:type,
							}
							$https('GET','confirmBalanceWater',params,res=>{
								if(res.data.errcode==0){
									uni.showToast({
										title: '提交成功',
										icon:'none',
										success:()=>{
											uni.$emit('updatebalance',()=>{})
											setTimeout(()=>{
												this.back();
											},1500)
										}
									});
								}else{
									uni.showToast({
										title: res.data.errmsg,
										icon:'none'
									});
								}
							})
				        }
				    }
				});
			},
			back(){
				// #ifdef H5
					window.history.back(-1);
				// #endif 
				// #ifndef H5
				uni.navigateBack();
				// #endif
			}
		}
	}
</script>

<style lang="scss" scoped>
.page{
	.content{
		padding:0 30rpx;
		font-size: 32rpx;
		>view{
			margin:54rpx 0;
			color:#9A9A9A;
			.prop{
				color:#191919;
			}
		}
		.btns{
			display: flex;
			font-size: 26rpx;
			justify-content: center;
			margin-top:160rpx;
			.btn{
				width: 280rpx;
				height: 80rpx;
				line-height: 80rpx;
				color:#fff;
				&:first-child{
					background: #4FA389;
					border-radius: 40rpx 0 0 40rpx;
				}
				&:last-child{
					background:#8FC4B2;
					border-radius: 0 40rpx 40rpx 0;
				}
			}
		}
	}
}
</style>
